﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DbMapping.Common;
using VideoCache.Server.Model;
using VideoCache.Server.BLL;
using VideoCache.Server.MVCWeb.Attributes;

namespace VideoCache.Server.MVCWeb.Areas.Admin.Controllers
{
    [ActionAuthorize(AuthorizeType.Administrator)]
    public class CompanyController : Controller
    {
        //
        // GET: /Admin/Company/

        public ActionResult Index(string keyword, int page = 1)
        {
            Conditions cons = new Conditions();

            if (!string.IsNullOrEmpty(keyword))
            {
                cons.Add(new ConditionItem(LinkType.And, AgentInfo.NameField, CompareType.Container, keyword));
                cons.Add(new ConditionItem(LinkType.Or, AgentInfo.IdField, CompareType.Equal, keyword));
            }

            Orders orders = new Orders();
            orders.Add(new OrderItem(AgentInfo.CreateTimeField, OrderDirection.Desc));

            int recordCount = 0;
            int pageSize = 30;

            var list = AgentBLL.FindPage(cons, orders, page, pageSize, ref recordCount);

            ViewBag.PageSize = pageSize;
            ViewBag.RecordCount = recordCount;

            return View(list);
        }

    }
}
